package com.shop2cn.iapi.sqoptrade.testcase;

import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.optrade.parameter.enums.CancelOrderTypeEnum;
import com.ymatou.iapi.optrade.parameter.req.ValidateRefundV2Req;
import com.ymatou.iapi.optrade.parameter.utill.Utils;
import com.ymatou.iapi.optrade.resp.Order;
import com.ymatou.iapi.optrade.resp.TradingServiceResp;
import com.ymatou.iapi.optrade.service.BargainGroupService;
import com.ymatou.iapi.optrade.service.ValidateRefundV2Call;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.TradingCallService;
import com.ymttest.database.sharding.db.sharding.model.OrderDetailPo;
import com.ymttest.database.sharding.db.sharding.model.OrderPo;
import com.ymttest.database.sharding.db.sharding.model.RefundBillPo;
import com.ymttest.database.sharding.db.sqlwapper.OrderShardingWapper;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.utils.DataUtil;

/**
 * 退货退款申请效验接口 FreeMaker Template自动生成代码
 */
@TestSuite
@Ignore
public class Ts_ValidateRefundV2 {

	private static ValidateRefundV2Req validateRefundReq;
	private static ValidateRefundV2Call applyvalidationCall;
	private static OrderShardingWapper orderShardingWapper = new OrderShardingWapper();

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("退货退款申请校验接口");
	}

	@Before
	public void caseUp() {
		validateRefundReq = new ValidateRefundV2Req();
		applyvalidationCall = new ValidateRefundV2Call();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(applyvalidationCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	/**
	 * 计算商品最大可退金额
	 * 
	 * @param po
	 * @return
	 */
	public static BigDecimal getOrderDetailPaidAmountExcludeFreight(
			OrderDetailPo po, int productCount) {

		BigDecimal refundAmount = Utils.zeroIfNull(po.getProductPrice())
				.multiply(new BigDecimal(po.getProductCount()))
				.add(Utils.zeroIfNull(po.getDiscount()))
				.subtract(Utils.zeroIfNull(po.getYmtCouponAmount()))
				.subtract(Utils.zeroIfNull(po.getSellerCouponAmount()))
				.subtract(Utils.zeroIfNull(po.getPromotionAmount()))
				.subtract(Utils.zeroIfNull(po.getThirdpartyDiscount()))
				.subtract(Utils.zeroIfNull(po.getYmtPromotionAmount()));

		if (po.getProductCount() != productCount) {

			refundAmount = refundAmount
					.divide(new BigDecimal(po.getProductCount()),
							MathContext.DECIMAL32)
					.setScale(2, RoundingMode.DOWN)
					.multiply(new BigDecimal(productCount));

		}

		return refundAmount;

	}

	/**
	 * 计算商品最大可退运费
	 * 
	 * @param po
	 * @return
	 */
	public static BigDecimal getMaxCanRefundFreight(Order order,
			BigDecimal productFreight) {

		long orderId = order.getOrderId();

		if (BigDecimal.ZERO.compareTo(productFreight) == 0) {

			return BigDecimal.ZERO;

		}

		List<RefundBillPo> res = orderShardingWapper
				.selectRefundBillListByOrderId(orderId);

		BigDecimal freight = res
				.stream()
				.filter(r -> r.getRefundBillStatus() == 1
						|| r.getRefundBillStatus() == 10)
				.map(f -> f.getFreight())
				.reduce(BigDecimal.ZERO, BigDecimal::add);

		return order.getOrderFreight().subtract(freight);

	}

	/**
	 * 
	 * @param order
	 * @param orderDetailPo
	 * @param refundCount
	 */
	private void verify(Order order, OrderDetailPo orderDetailPo,
			int refundCount) {

		BigDecimal maxCanRefundAmount = getOrderDetailPaidAmountExcludeFreight(
				orderDetailPo, refundCount);

		BigDecimal maxCanRefundFreight = getMaxCanRefundFreight(order,
				orderDetailPo.getFreight());

		Logger.verifyEquals("true", applyvalidationCall.getString("success"),
				"验证返回码");

		DataUtil.verifyDecimalEquals(maxCanRefundAmount, new BigDecimal(
				applyvalidationCall.getString("maxCanRefundAmount")),
				"验证maxCanRefundAmount");

		DataUtil.verifyDecimalEquals(maxCanRefundFreight, new BigDecimal(
				applyvalidationCall.getString("maxCanRefundFreight")),
				"验证maxCanRefundFreight");
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_001() {
		Logger.start(true, "用户下单后申请效验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService.placeOrder1(
					true, false);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(String.format("申请退款金额不能大于实际可退款金额", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_002() {
		Logger.start(true, "用户支付后接单前效验成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService.payOrder();
			Order order = placeOrderResp.getOrderList().get(0);
			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(order.getOrderDetailPoList().get(0)
					.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_003() {
		Logger.start(true, "商家接单前取消订单,效验成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.cancelOrderBeforePaid(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ERR_ORDER_CANCELLED",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(String.format("订单%s已取消，不能退货退款", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_004() {
		Logger.start(true, "商家接单后,退货退款校验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderAccept();

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(order.getOrderDetailPoList().get(0)
					.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {

			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_005() {
		Logger.start(true, "商家接单后取消订单,效验成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderAccept();

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long userId = placeOrderResp.getUserId();

			// 取消订单
			TradingCallService.cancelOrder(orderId,
					CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER, userId);

			Logger.comment("前置数据准备结束");
			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ERR_ORDER_CANCELLED",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(String.format("订单%s已取消，不能退货退款", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ValidateRefundV2_006() {
		Logger.start(false, "订单退货退款中,申请校验的金额小于等于可退款金额");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.placeOrder3(false);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			long userId = placeOrderResp.getUserId();
			long tradingId = placeOrderResp.getTradingId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 付款
			TradingCallService.payOrder(userId, amount, tradingId);

			// 卖家接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			BigDecimal maxCanRefundAmount = getOrderDetailPaidAmountExcludeFreight(
					placeOrderResp.getOrderList().get(0).getOrderDetailPoList()
							.get(0), validateRefundReq.getApplyRefundCount());

			BigDecimal maxCanRefundFreight = getMaxCanRefundFreight(order,
					order.getOrderDetailPoList().get(0).getFreight());

			Logger.verifyEquals("true",
					applyvalidationCall.getString("success"), "验证返回码");

			DataUtil.verifyDecimalEquals(maxCanRefundAmount, new BigDecimal(
					applyvalidationCall.getString("maxCanRefundAmount")),
					"验证maxCanRefundAmount");

			DataUtil.verifyDecimalEquals(maxCanRefundFreight, new BigDecimal(
					applyvalidationCall.getString("maxCanRefundFreight")),
					"验证maxCanRefundFreight");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ValidateRefundV2_007() {
		Logger.start(false, "订单退货退款中,申请校验的金额大于最大可退款金额");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderApplyRefund();

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(2);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(String.format("申请退款金额不能大于实际可退款金额", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_008() {
		Logger.start(true, "用户收货之后申请校验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderConfirmReceive();

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);
			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ValidateRefundV2_009() {
		Logger.start(false, "订单号不存在申请效验");
		try {

			validateRefundReq.setOrderId(11111);
			validateRefundReq.setCatalogId("123");
			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);

			validateRefundReq.setRefundBillNo(String.format("TK%s", 11111));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderNotExists",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("订单不存在", validateRefundReq.getOrderId()),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ValidateRefundV2_010() {
		Logger.start(false, "订单号为null申请效验");
		try {
			// validateRefundReq.setOrderId(111111);
			validateRefundReq.setCatalogId("123");
			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);

			validateRefundReq.setRefundBillNo(String.format("TK%s", 11111));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ILLEGAL_ARGUMENT",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("orderId:订单号未提供",
							validateRefundReq.getOrderId()),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_014() {
		Logger.start(true, "商家发货后,退货退款校验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderDelivery();

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_015() {
		Logger.start(true, "确认收货15天内,退货退款校验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderConfirmReceive();

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();

			new DefaultWapper().updateOrderConfirmedTimeByOrderId(orderId);

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();

			OrderPo record = new OrderPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.DAY_OF_MONTH, -10);
			;

			record.setOrderId(orderId);
			record.setReceiveTime(calendar.getTime());

			orderShardingWapper.orderMapper.updateByPrimaryKeySelective(record);

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_017() {
		Logger.start(true, "商品申请退款金额大于(商品可退金额+订单总运费)");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.placeOrder3(false);

			Order order = placeOrderResp.getOrderList().get(0);

			Long orderId = order.getOrderId();

			// 支付
			TradingCallService.payOrder(placeOrderResp.getUserId(),
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			// 接单
			TradingCallService.sellerAcceptOrder(order.getSellerId(), orderId);

			Logger.comment("前置数据准备结束");

			// 第一个商品
			OrderDetailPo orderInfoPo = order.getOrderDetailPoList().get(0);

			validateRefundReq.setApplyRefundAmount(orderInfoPo
					.getProductPrice()
					.multiply(new BigDecimal(orderInfoPo.getProductCount()))
					.add(order.getOrderFreight()).add(BigDecimal.ONE));
			validateRefundReq
					.setApplyRefundCount(orderInfoPo.getProductCount());
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("订单%s申请退款金额不能大于商品最大可退款金额", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_018() {
		Logger.start(true, "订单商品不是包邮,商品退款加退部分商品运费");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderAccept();

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();

			// 第一个订单下的第一个商品
			OrderDetailPo orderInfoPo = order.getOrderDetailPoList().get(0);

			int productNum = orderInfoPo.getProductCount();

			BigDecimal productFreight = orderInfoPo.getFreight();

			BigDecimal refundProductFreight = productFreight
					.subtract(new BigDecimal(2));

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(refundProductFreight
					.add(refoundAmout));

			validateRefundReq
					.setApplyRefundCount(orderInfoPo.getProductCount());
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_019() {
		Logger.start(true, "订单商品不是包邮,商品退款及退超过商品的运费，但不超过订单总运费");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.placeOrder3(false);

			Order order = placeOrderResp.getOrderList().get(0);

			Long orderId = order.getOrderId();

			// 支付
			TradingCallService.payOrder(placeOrderResp.getUserId(),
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			// 接单
			TradingCallService.sellerAcceptOrder(order.getSellerId(), orderId);

			// 第一个订单下的第一个商品
			OrderDetailPo orderInfoPo = order.getOrderDetailPoList().get(0);

			int productNum = orderInfoPo.getProductCount();

			BigDecimal productFreight = orderInfoPo.getFreight();

			BigDecimal refundProductFreight = productFreight
					.add(new BigDecimal(2));

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(refundProductFreight
					.add(refoundAmout));

			validateRefundReq
					.setApplyRefundCount(orderInfoPo.getProductCount());
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_020() {
		Logger.start(true, "退款商品数量大于实际数量");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderAccept();

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();

			// 第一个订单下的第一个商品
			OrderDetailPo orderInfoPo = order.getOrderDetailPoList().get(0);

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq
					.setApplyRefundCount(orderInfoPo.getProductCount() + 1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ERR_CONDITION_NOTMATCH",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(String.format("申请退商品数量不能大于实际商品数量", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_021() {
		Logger.start(true, "订单商品不是包邮,申请单个商品退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderAccept();

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();

			// 第一个订单下的第一个商品
			OrderDetailPo orderInfoPo = order.getOrderDetailPoList().get(0);

			int productNum = orderInfoPo.getProductCount();

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			// 单件商品可退金额
			BigDecimal oneProRefund = refoundAmout.divide(new BigDecimal(
					productNum), 2, BigDecimal.ROUND_DOWN);

			Logger.comment("前置数据准备结束");

			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(orderInfoPo.getCatalogId());

			validateRefundReq.setApplyRefundAmount(oneProRefund);

			validateRefundReq.setApplyRefundCount(1);

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);

			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_022() {
		Logger.start(true, "订单商品不是包邮,申请单个商品退款加部分商品运费");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderAccept();

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();

			// 第一个订单下的第一个商品
			OrderDetailPo orderInfoPo = order.getOrderDetailPoList().get(0);

			int productNum = orderInfoPo.getProductCount();

			BigDecimal productFreight = orderInfoPo.getFreight();

			BigDecimal refundProductFreight = productFreight
					.subtract(new BigDecimal(2));

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			// 单件商品可退金额

			BigDecimal oneProRefund = refoundAmout.divide(new BigDecimal(
					productNum), 2, BigDecimal.ROUND_DOWN);
			Logger.comment("前置数据准备结束");

			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(orderInfoPo.getCatalogId());

			validateRefundReq.setApplyRefundAmount(oneProRefund
					.add(refundProductFreight));

			validateRefundReq.setApplyRefundCount(1);

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);

			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_023() {
		Logger.start(true, "订单商品不是包邮,申请单个商品退款加上不超过订单总运费");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.placeOrder3(false);

			Order order = placeOrderResp.getOrderList().get(0);

			Long orderId = order.getOrderId();

			// 支付
			TradingCallService.payOrder(placeOrderResp.getUserId(),
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			// 接单
			TradingCallService.sellerAcceptOrder(order.getSellerId(), orderId);

			// 第一个订单下的第一个商品
			OrderDetailPo orderInfoPo = order.getOrderDetailPoList().get(0);

			int productNum = orderInfoPo.getProductCount();

			BigDecimal productFreight = orderInfoPo.getFreight();

			BigDecimal refundProductFreight = productFreight
					.add(new BigDecimal(2));

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			// 单件商品可退金额
			BigDecimal oneProRefund = refoundAmout.divide(new BigDecimal(
					productNum), 2, BigDecimal.ROUND_DOWN);

			Logger.comment("前置数据准备结束");

			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(orderInfoPo.getCatalogId());

			validateRefundReq.setApplyRefundAmount(oneProRefund
					.add(refundProductFreight));
			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));
			validateRefundReq.setApplyRefundCount(1);

			applyvalidationCall.setData(validateRefundReq);

			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_024() {
		Logger.start(true, "订单商品不是包邮,申请单个商品退款加订单总运费");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.placeOrder3(false);

			Order order = placeOrderResp.getOrderList().get(0);

			BigDecimal orderFreight = order.getOrderFreight();

			Long orderId = order.getOrderId();

			// 支付
			TradingCallService.payOrder(placeOrderResp.getUserId(),
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			// 接单
			TradingCallService.sellerAcceptOrder(order.getSellerId(), orderId);

			// 第一个订单下的第一个商品
			OrderDetailPo orderInfoPo = order.getOrderDetailPoList().get(0);

			int productNum = orderInfoPo.getProductCount();

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			// 单件商品可退金额
			BigDecimal oneProRefund = refoundAmout.divide(new BigDecimal(
					productNum), 2, BigDecimal.ROUND_DOWN);

			Logger.comment("前置数据准备结束");

			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(orderInfoPo.getCatalogId());

			validateRefundReq.setApplyRefundAmount(oneProRefund
					.add(orderFreight));

			validateRefundReq.setApplyRefundCount(1);

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);

			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_025() {
		Logger.start(true, "订单商品不是包邮,申请单个商品退款加上超过订单总运费");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.placeOrder3(false);

			Order order = placeOrderResp.getOrderList().get(0);

			BigDecimal orderFreight = order.getOrderFreight();

			Long orderId = order.getOrderId();

			// 支付
			TradingCallService.payOrder(placeOrderResp.getUserId(),
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			// 接单
			TradingCallService.sellerAcceptOrder(order.getSellerId(), orderId);

			// 第一个订单下的第一个商品
			OrderDetailPo orderInfoPo = order.getOrderDetailPoList().get(0);

			int productNum = orderInfoPo.getProductCount();

			BigDecimal refundProductFreight = orderFreight
					.add(new BigDecimal(2));

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			// 单件商品可退金额
			BigDecimal oneProRefund = refoundAmout.divide(new BigDecimal(
					productNum), 2, BigDecimal.ROUND_DOWN);

			Logger.comment("前置数据准备结束");

			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(orderInfoPo.getCatalogId());

			validateRefundReq.setApplyRefundAmount(oneProRefund
					.add(refundProductFreight));

			validateRefundReq
					.setApplyRefundCount(orderInfoPo.getProductCount());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);

			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_026() {
		Logger.start(true, "订单锁定后申请效验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderAccept();

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			// 锁定订单
			TradingCallService.markOrderLock(orderId, 1);

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("该订单已被客服锁定，暂时无法对该订单进行后续操作",
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_027() {
		Logger.start(true, "虚拟商品不能发起退货退款");

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = BargainGroupService
					.placeVirtualProduct();

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(String.format("申请退款金额不能大于实际可退款金额", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

//	@Test
//	@Category({ P1.class })
//	@TestCase
//	public void Tc_ValidateRefundV2_028() {
//		Logger.start(true, "订单里有包邮非包邮混合商品,包邮商品全退+退部分运费");
//		try {
//
//			TradingServiceResp placeOrderResp = Ts_ApplySalesRefund
//					.placeOrder3();
//
//			Order order = placeOrderResp.getOrderList().get(0);
//
//			long sellerId = order.getSellerId();
//			long userId = placeOrderResp.getUserId();
//			long tradingId = placeOrderResp.getTradingId();
//			long orderId = order.getOrderId();
//			BigDecimal amount = placeOrderResp.getPayableAmount();
//
//			// 付款
//			TradingCallService.payOrder(userId, amount, tradingId);
//			// 卖家接单
//			TradingCallService.sellerAcceptOrder(sellerId, orderId);
//
//			validateRefundReq.setOrderId(orderId);
//
//			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(1);
//
//			String catalogId = orderDetailPo.getCatalogId();
//
//			int productNum = orderDetailPo.getProductCount();
//
//			// 可以退款的订单总价格 商品价格 X 数量+运费
//			BigDecimal refoundAmout = (orderDetailPo.getProductPrice())
//					.multiply(new BigDecimal(productNum))
//					.subtract(orderDetailPo.getSellerCouponAmount())
//					.subtract(orderDetailPo.getYmtCouponAmount())
//					.subtract(orderDetailPo.getYmtPromotionAmount())
//					.subtract(
//							Utils.zeroIfNull(orderDetailPo
//									.getThirdpartyDiscount()))
//					.subtract(orderDetailPo.getRebatePaidAmount())
//					.add(orderDetailPo.getFreight());
//
//			validateRefundReq.setOrderId(orderId);
//
//			validateRefundReq.setApplyRefundCount(productNum);
//			validateRefundReq.setApplyRefundAmount(refoundAmout
//					.add(BigDecimal.ONE));
//			validateRefundReq.setCatalogId(catalogId);
//
//			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));
//
//			applyvalidationCall.setData(validateRefundReq);
//			applyvalidationCall.callService();
//
//			Logger.verifyEquals("false",
//					applyvalidationCall.getString("success"), "验证返回码");
//
//			Logger.verifyEquals("ErrOrderAmountNotMatch",
//					applyvalidationCall.getString("errorCode"), "验证返回码");
//
//			Logger.verifyEquals(
//					String.format("订单%s申请退款金额不能大于商品最大可退款金额", orderId),
//					applyvalidationCall.getString("errorMessage"),
//					"验证errorMessage");
//
//		} catch (Exception e) {
//			Logger.fail(e);
//		}
//	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_029() {
		Logger.start(true, "购买海淘达人会员订单，申请退货退款失败");

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.placeMultiProAnlihuiOrder(BigDecimal.TEN, false, 3);

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ERR_STATUS_NOTMATCH",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(String.format("已购买的安利会员订单不能发起退货退款", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_030() {
		Logger.start(true, "订单商品满减包邮,申请单个商品退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.placeOrder(true);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long userId = placeOrderResp.getUserId();
			long tradingId = placeOrderResp.getTradingId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			BigDecimal payAmount = placeOrderResp.getPayableAmount();

			// 支付订单
			TradingCallService.payOrder(userId, payAmount, tradingId);
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			// 商家发货
			TradingCallService.delivery(sellerId, orderId, false);
			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);

			Thread.sleep(5000);

			Order order = placeOrderResp.getOrderList().get(0);

			// 第一个订单下的第一个商品
			OrderDetailPo orderInfoPo = order.getOrderDetailPoList().get(0);

			int productNum = orderInfoPo.getProductCount();

			// 计算订单总价格 商品价格 X 数量
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			// 单件商品可退金额
			BigDecimal oneProRefund = refoundAmout.divide(new BigDecimal(
					productNum), 2, BigDecimal.ROUND_DOWN);

			Logger.comment("前置数据准备结束");

			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(orderInfoPo.getCatalogId());

			validateRefundReq.setApplyRefundAmount(oneProRefund);

			validateRefundReq.setApplyRefundCount(1);

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);

			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_031() {
		Logger.start(true, "订单商品满减包邮,申请单个商品退款+运费，申请失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.placeOrder(true);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long userId = placeOrderResp.getUserId();
			long tradingId = placeOrderResp.getTradingId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			BigDecimal payAmount = placeOrderResp.getPayableAmount();

			// 支付订单
			TradingCallService.payOrder(userId, payAmount, tradingId);
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			// 商家发货
			TradingCallService.delivery(sellerId, orderId, false);
			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);

			Thread.sleep(5000);

			Order order = placeOrderResp.getOrderList().get(0);

			// 第一个订单下的第一个商品
			OrderDetailPo orderInfoPo = order.getOrderDetailPoList().get(0);

			int productNum = orderInfoPo.getProductCount();

			// 计算订单总价格 商品价格 X 数量
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount())
					.add(orderInfoPo.getFreight());

			// 单件商品可退金额
			BigDecimal oneProRefund = refoundAmout.divide(new BigDecimal(
					productNum), 2, BigDecimal.ROUND_DOWN);

			Logger.comment("前置数据准备结束");

			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(orderInfoPo.getCatalogId());

			validateRefundReq.setApplyRefundAmount(oneProRefund);

			validateRefundReq.setApplyRefundCount(1);

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);

			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(String.format("订单%s申请退款金额不能大于商品最大可退款金额", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
